//: C16:Stackt.cpp
// From Thinking in C++, 2nd Edition
// Available at http://www.BruceEckel.com
// (c) Bruce Eckel 1999
// Copyright notice in Copyright.txt
// Test simple stack template
#include "Stackt.h"
#include "../require.h"
#include <iostream>
using namespace std;

// For interest, generate Fibonacci numbers:
int fibonacci(int n)
{
    const int sz = 100;
    require(n < sz);
    static int f[sz]; // Initialized to zero
    f[0] = f[1] = 1;
    // Scan for unfilled array elements:
    int i;
    for (i = 0; i < sz; i++)
        if (f[i] == 0) break;
    while (i <= n) {
        f[i] = f[i-1] + f[i-2];
        i++;
    }
    return f[n];
}

int main()
{
    Stackt<int> is;
    for (int i = 0; i < 20; i++)
        is.push(fibonacci(i));
    // Traverse with an iterator:
    StacktIter<int> it(is);
    for (int j = 0; j < 20; j++)
        cout << it++ << endl;
    for (int k = 0; k < 20; k++)
        cout << is.pop() << endl;
} ///:~
